// Decompiled by:       Fernflower v0.8.6
// Date:                03.08.2014 10:26:33
// Copyright:           2008-2012, Stiver
// Home page:           http://www.neshkov.com/ac_decompiler.html

package com.dynamixsoftware.printershare.data;

import java.net.HttpURLConnection;
import java.net.URL;

import com.dynamixsoftware.printershare.data.SoapEnvelope;

public class SoapService {

	private String service_url;
	private String user_agent;

	public SoapService(String paramString1, String paramString2) {
		this.service_url = paramString1;
		this.user_agent = paramString2;
	}

	public SoapEnvelope doAction(SoapEnvelope paramSoapEnvelope)
			throws Exception {
		URL localURL = new URL(this.service_url);
		HttpURLConnection localHttpURLConnection = null;
		int i = 0;
		try {
			int j;
			for (;;) {
				localHttpURLConnection = (HttpURLConnection) localURL
						.openConnection();
				localHttpURLConnection.setConnectTimeout(15000);
				localHttpURLConnection.setReadTimeout(15000);
				localHttpURLConnection.setDoInput(true);
				localHttpURLConnection.setDoOutput(true);
				localHttpURLConnection.setUseCaches(false);
				localHttpURLConnection.setRequestMethod("POST");
				localHttpURLConnection.setRequestProperty("User-Agent",
						this.user_agent);
				localHttpURLConnection.setRequestProperty("Content-Type",
						"text/xml; charset=utf-8");
				localHttpURLConnection.setRequestProperty("SOAPAction",
						"http://www.printeranywhere.com/"
								+ paramSoapEnvelope.action_name);
				XmlUtil.writeDocument(paramSoapEnvelope.doc,
						localHttpURLConnection.getOutputStream());
				j = localHttpURLConnection.getResponseCode();
				if (j == 200) {
					break label226;
				}
				if (i >= 3) {
					break;
				}
				i++;
				Thread.sleep(i * 1000);
				if (localHttpURLConnection != null) {
				}
				try {
					localHttpURLConnection.disconnect();
					localHttpURLConnection = null;
				} catch (Exception localException3) {
					localException3.printStackTrace();
				}
			}
			throw new Exception("Can't connect to " + this.service_url
					+ ". HTTP error " + j);
		} finally {
			if (localHttpURLConnection == null) {
			}
		}
		try {
			localHttpURLConnection.disconnect();
			throw localObject;
			// label226:
			SoapEnvelope localSoapEnvelope = new SoapEnvelope(
					paramSoapEnvelope.action_name,
					paramSoapEnvelope.action_name + "Result",
					"response",
					XmlUtil.getDocument(localHttpURLConnection.getInputStream()));
			if (localHttpURLConnection != null) {
			}
			try {
				localHttpURLConnection.disconnect();
				return localSoapEnvelope;
			} catch (Exception localException2) {
				localException2.printStackTrace();
				return localSoapEnvelope;
			}
		} catch (Exception localException1) {
			for (;;) {
				localException1.printStackTrace();
			}
		}
	}

	public String getUserAgent() {
		return this.user_agent;
	}
}
